package cn.edu.xmu.experiment.PulseComms.repository;


import cn.edu.xmu.experiment.PulseComms.entity.Message;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface MessageRepository extends JpaRepository<Message, Long> {

    @Query("SELECT m FROM Message m " +
            "WHERE (m.sender = :username OR m.receiver = :username) " +
            "AND m.groupName IS NULL")
    List<Message> findPrivateMessagesByUsername(@Param("username") String username);

    List<Message> findByGroupName(String groupName);
}